package com.ruoyi.syf.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.syf.domain.RiskAccidentType;
import com.ruoyi.syf.service.IRiskAccidentTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事故类型
 *
 * @author yr
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/syf/type")
public class RiskAccidentTypeController extends BaseController
{
    @Autowired
    private IRiskAccidentTypeService riskAccidentTypeService;

    /**
     * 查询事故类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskAccidentType riskAccidentType)
    {
        startPage();
        List<RiskAccidentType> list = riskAccidentTypeService.list(riskAccidentType);
        return getDataTable(list);
    }

    /**
     * 获取事故类型详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(riskAccidentTypeService.selectRiskAccidentTypeById(id));
    }

    /**
     * 新增事故类型
     */
    @PreAuthorize("@ss.hasPermi('syf:type:add')")
    @Log(title = "事故类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskAccidentType riskAccidentType)
    {
        return toAjax(riskAccidentTypeService.insertRiskAccidentType(riskAccidentType));
    }

    /**
     * 修改事故类型
     */
    @PreAuthorize("@ss.hasPermi('syf:type:edit')")
    @Log(title = "事故类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskAccidentType riskAccidentType)
    {
        return toAjax(riskAccidentTypeService.updateRiskAccidentType(riskAccidentType));
    }

    /**
     * 删除事故类型
     */
    @PreAuthorize("@ss.hasPermi('syf:type:remove')")
    @Log(title = "事故类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskAccidentTypeService.deleteRiskAccidentTypeByIds(ids));
    }
}
